const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const BooksSchema = new Schema({
  isbnCode: {
    type: String,
    required: true,
    unique: true,
  },
  userId: {
    type: String,
    ref: 'UserSchema', // 关联UserSchema的_id字段，进行连表查询
    required: true,
  },
  avrgRating: String,
  title: String,
  image: String,
  alt: String,
  publisher: String,
  summary: String,
  price: String,
  formatTags: {
    type: Array,
    default: [],
  },
  author: {
    type: Array,
    default: [],
  },
  accessCount: { // 访问量
    type: Number,
    default: 0,
  },
});

mongoose.model('BooksSchema', BooksSchema);